package com.zyg.cod.test;

import cn.hutool.core.bean.BeanUtil;
import com.zyg.cod.test.person.StudentVO;

import java.util.*;

/**
 * @Dsc:  测试构建数据对象
 * @Author: zyg
 * @Date: 2021/1/28
 */
public class DataUtil {


	/**
	 * 获取基础信息map
	 * @return
	 */
	public static Map<String,Object> getMapData(){
		HashMap<String, Object> map = new HashMap<>();
		//学生主体列表
		List<Student> students = new ArrayList<>();
		students.add(new Student(1, "zyg", 26, new Date()));
		students.add(new Student(2, "nyy", 25, new Date()));

		List<ClazzInfo> clazzInfos = new ArrayList<>();
		clazzInfos.add(new ClazzInfo(1, 2, "181班", 181));
		clazzInfos.add(new ClazzInfo(2, 1, "171班", 171));

		List<FimanyInfo> fimanyInfos = new ArrayList<>();
		fimanyInfos.add(new FimanyInfo(1, 1, "旧寨"));
		fimanyInfos.add(new FimanyInfo(2, 2, "巍峨"));

		List<RelationInfo> relationInfos = new ArrayList<>();
		relationInfos.add(new RelationInfo(1, new Date(),2, "父亲", "农氏"));
		relationInfos.add(new RelationInfo(2,new Date(), 2, "母亲", "农氏"));
		relationInfos.add(new RelationInfo(3, new Date(),1, "父亲", "钟氏"));
		relationInfos.add(new RelationInfo(4,new Date(), 1, "母亲", "妈氏"));
		map.put("Student", students);
		map.put("ClazzInfo", clazzInfos);
		map.put("FimanyInfo", fimanyInfos);
		map.put("RelationInfo", relationInfos);

		return map;

	}

	/**
	 * 获取学生信息树
	 * @return
	 */
	public static List<StudentDTO> getStudentList(){
		//基础数据库
		//学生主体段
		List<Student> students = new ArrayList<>();
		students.add(new Student(1, "zyg", 26, new Date()));
		students.add(new Student(2, "nyy", 25, new Date()));
		//班级信息段
		List<ClazzInfo> clazzInfos = new ArrayList<>();
		clazzInfos.add(new ClazzInfo(1, 2, "181班", 181));
		clazzInfos.add(new ClazzInfo(2, 1, "171班", 171));
		//家庭信息段
		List<FimanyInfo> fimanyInfos = new ArrayList<>();
		fimanyInfos.add(new FimanyInfo(1, 1, "旧寨"));
		fimanyInfos.add(new FimanyInfo(2, 2, "巍峨"));
		//社会信息段
		List<RelationInfo> relationInfos = new ArrayList<>();
		relationInfos.add(new RelationInfo(1,new Date(), 2, "父亲", "农氏"));
		relationInfos.add(new RelationInfo(2,new Date(), 2, "母亲", "农氏"));
		relationInfos.add(new RelationInfo(3,new Date(), 1, "父亲", "钟氏"));
		relationInfos.add(new RelationInfo(4,new Date(),1, "母亲", "妈氏"));


		/**数据树构建：树形列表
		 * 学生与班级信息一对一，
		 * 学生与家庭信息一对一
		 * 学生与社会关系一对多
		 *
		 */

		List<StudentDTO> vos = new ArrayList<>(10);
		StudentDTO studentDTO = null;
		ClazzInfo clazzInfo = null;
		FimanyInfo fimanyInfo = null;
		List<RelationInfo> relations = null;
		for (Student student : students) {
			//学生基础信息
			studentDTO = (StudentDTO) BeanUtil.toBean(student, StudentDTO.class);
			//设置班级
			for (ClazzInfo info : clazzInfos) {
				if (info.getUid() == student.getUid()) {
					clazzInfo = info;
				}
			}
			studentDTO.setClazzInfos(clazzInfo);

			//设置家庭信息
			for (FimanyInfo info : fimanyInfos) {
				if (info.getUid() == student.getUid()) {
					fimanyInfo = info;
				}
			}
			studentDTO.setFimanyInfos(fimanyInfo);
			//设置社会关系信息
			relations = new ArrayList<>();
			for (RelationInfo info : relationInfos) {
				if (info.getUid() == student.getUid()) {
					relations.add(info);
				}
			}
			studentDTO.setRelationInfos(relations);
			//添加到新的树
			vos.add(studentDTO);
		}
		return vos;
	}

	/**
	 * 获取排列好的学生基础信息 List<Map<String,Object>>
	 *
	 *     以学生为单位，每个学生下的所有信息，
	 *     每一学生都是一个Map,每个map下都有特定的信息段，是一个list，如果为多个，那么就是一对多
	 */

	public static List<StudentVO> getStudentData(){
		//基础数据库
		//学生主体段
		List<Student> students = new ArrayList<>();
		students.add(new Student(1, "zyg", 26, new Date()));
		students.add(new Student(2, "nyy", 25, new Date()));
		//班级信息段
		List<ClazzInfo> clazzInfos = new ArrayList<>();
		clazzInfos.add(new ClazzInfo(1, 2, "181班", 181));
		clazzInfos.add(new ClazzInfo(2, 1, "171班", 171));
		//家庭信息段
		List<FimanyInfo> fimanyInfos = new ArrayList<>();
		fimanyInfos.add(new FimanyInfo(1, 1, "旧寨"));
		fimanyInfos.add(new FimanyInfo(2, 2, "巍峨"));
		//社会信息段
		List<RelationInfo> relationInfos = new ArrayList<>();
		relationInfos.add(new RelationInfo(1,new Date(), 2, "父亲", "农氏"));
		relationInfos.add(new RelationInfo(2,new Date(), 2, "母亲", "农氏"));
		relationInfos.add(new RelationInfo(3,new Date(), 1, "父亲", "钟氏"));
		relationInfos.add(new RelationInfo(4 ,new Date(),1, "母亲", "妈氏"));


		//创建最终返回对象
		List<StudentVO> list = new ArrayList<>();
		//创建每个学生主体的主题对象:key是学生列表的索引，value是
		StudentVO person = null;


		/**数据树构建：树形列表
		 * 学生与班级信息一对一，
		 * 学生与家庭信息一对一
		 * 学生与社会关系一对多
		 *
		 */

		List<Student> stus = null;
		List<ClazzInfo> clazzs = null;
		List<FimanyInfo> fimanys = null;
		List<RelationInfo> relas = null;


		for (Student student : students) {
			//创建学生主体
			person = new StudentVO();

			//学生基础信息
			stus = new ArrayList<Student>(1);
			stus.add(student);
			person.setStudents(stus);
			//设置班级
			clazzs = new ArrayList<ClazzInfo>(1);
			for (ClazzInfo info : clazzInfos) {
				if (info.getUid() == student.getUid()) {
					clazzs.add(info);
				}
			}
			person.setClazzInfos(clazzs);
			//设置家庭信息
			fimanys = new ArrayList<FimanyInfo>(1);
			for (FimanyInfo info : fimanyInfos) {
				if (info.getUid() == student.getUid()) {
					fimanys.add(info);
				}
			}
			person.setFimanyInfos(fimanys);
			//设置社会关系信息
			relas = new ArrayList<>();
			for (RelationInfo info : relationInfos) {
				if (info.getUid() == student.getUid()) {
					info.setRelation(null);
					relas.add(info);
				}
			}
			person.setRelationInfos(relas);

			list.add(person);
		}
		return list;
	}
}
